﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BanmaytinhDAL
{
    public class HangsanxuatDAL : SQLDataProvider
    {
        public  HangsanxuatInfo Hangsanxuat_GetById(string Mahangsanxuat)
        {
            BanmaytinhDAL.HangsanxuatInfo obj = new BanmaytinhDAL.HangsanxuatInfo();
           
            using (SqlCommand dbCmd = new SqlCommand("sp_Hangsanxuat_GetById", GetConnection()))
			{
				dbCmd.CommandType = CommandType.StoredProcedure;
				dbCmd.Parameters.Add(new SqlParameter("@Id", Mahangsanxuat));
				SqlDataReader dr = dbCmd.ExecuteReader();
				if (dr.HasRows)
				{
					while (dr.Read())
					{
						obj = obj.HangsanxuatIDataReader(dr);
					}
				}
                dr.Close();

			}
			return obj;
        }
        public List<HangsanxuatInfo> Hangsanxuat_GetByAll()
        {
            List<BanmaytinhDAL.HangsanxuatInfo> list = new List<BanmaytinhDAL.HangsanxuatInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Hangsanxuat_GetByAll", GetConnection()))
            {
                BanmaytinhDAL.HangsanxuatInfo obj = new BanmaytinhDAL.HangsanxuatInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.HangsanxuatIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }


        public  bool Insert(HangsanxuatInfo obj)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "sp_Hangsanxuat_Insert";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Tenhangsanxuat", (obj.Tenhangsanxuat == null) ? String.Empty : obj.Tenhangsanxuat);
                    
                    Database.db.ExecuteNonQuery(cmd);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public  bool Update(HangsanxuatInfo obj)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "sp_Hangsanxuat_Update";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Mahangsanxuat", (obj.Mahangsanxuat == null) ? String.Empty : obj.Mahangsanxuat);
                    cmd.Parameters.AddWithValue("@Tenhangsanxuat", (obj.Tenhangsanxuat == null) ? String.Empty : obj.Tenhangsanxuat);
                    
                    Database.db.ExecuteNonQuery(cmd);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public  bool Delete(string Mahangsanxuat)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "sp_Hangsanxuat_Delete";
                    cmd.Parameters.AddWithValue("@Mahangsanxuat", Mahangsanxuat);
                    Database.db.ExecuteNonQuery(cmd);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }



        
    }

}
